#include<stdio.h>
#include<string.h>
#include<unistd.h>
#include <sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>

int main()
{
  umask(0);
  // int fd  = open("log.txt", O_CREAT | O_WRONLY | O_TRUNC, 0666);
  //int fd  = open("log.txt", O_CREAT | O_WRONLY | O_APPEND, 0666);
  int fd  = open("log.txt", O_RDONLY);
  if(fd < 0)
  {
    perror("open");
    return 1;
  }
  printf("fd:%d\n",fd);

  while(1)
  {
    char buffer[64];
    int n = read(fd,buffer,sizeof(buffer)-1);
    if(n>0)
    {
      buffer[n] = 0;
      printf("%s",buffer);
    }
    else if(n == 0)
    {
      break;
    }
  }
  //const char *msg = "hello world\n";
  //int cnt = 5;
 // while(cnt)
 // {
 //   write(fd,msg,strlen(msg));
 //   cnt--;
 // }
 // close(fd);
  return 0;
}
